/**
 * @projectName CollegeEmploymentNetwork
 * @package com.kzj.CollegeEmploymentNetwork.config
 * @className com.kzj.CollegeEmploymentNetwork.config.ShrioConfig
 * @copyright Copyright 2025 Thunisoft, Inc All rights reserved.
 */
package com.kzj.CollegeEmploymentNetwork.shiro.config;

import org.apache.shiro.realm.Realm;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * ShrioConfig
 * @description
 * @author KZJ
 * @date 2025/1/23 20:39
 * @version TODO
 */
@Configuration
public class ShiroConfiguration {
//    @Bean
//    public Realm realm(){
//        return new MyAuthorizingRealm();
//    }
    @Bean
    public DefaultWebSecurityManager defaultWebSecurityManager(Realm realm){
        return new DefaultWebSecurityManager(realm);
    }
    @Bean
    public ShiroFilterFactoryBean shiroFilterFactoryBean(DefaultWebSecurityManager defaultWebSecurityManager){
        ShiroFilterFactoryBean shiroFilterFactoryBean=new ShiroFilterFactoryBean();
        //给ShiroFilter配置安全管理器
        shiroFilterFactoryBean.setSecurityManager(defaultWebSecurityManager);
        //配置公共资源
        //配置受限资源
        Map<String,String> map=new HashMap<>();
        map.put("/","authc");//authc 表示这个资源受限
        shiroFilterFactoryBean.setFilterChainDefinitionMap(map);

        shiroFilterFactoryBean.setLoginUrl("/login");
        return shiroFilterFactoryBean;
    }

}